﻿////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// <copyright>Copyright 2008-2011 Andreas Huber Doenni</copyright>
// Distributed under the GNU General Public License version 2 (GPLv2).
// See accompanying file License.txt or copy at http://phuse.codeplex.com/license.
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace Phuse.Mime
{
    using System;
    using System.Collections.Generic;
    using System.IO;
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    using Phuse.UnitTesting;

    /// <summary>Tests the <see cref="Message"/> class.</summary>
    [TestClass]
    public sealed class MessageVisitorTest : TestBase
    {
        ////////////////////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>Tests exceptions.</summary>
        [TestMethod]
        public void ExceptionTest()
        {
            AssertThrow<NotImplementedException>(() => new MyBody().Accept(new MyMessageVisitor(1)));
            AssertThrow<NotImplementedException>(() => new MyEntity().Accept(new MyMessageVisitor(1)));
            AssertThrow<ArgumentOutOfRangeException>(() => new MyMessageVisitor(-1).ToString());
        }

        /// <summary>Our visitor.</summary>
        private sealed class MyMessageVisitor : MessageVisitor
        {
            /// <summary>Does nothing.</summary>
            public override void OnVisit(ApplicationBody visitable)
            {
            }

            /// <summary>Does nothing.</summary>
            public override void OnVisit(ImageBody visitable)
            {
            }

            /// <summary>Does nothing.</summary>
            public override void OnVisit(TextBody visitable)
            {
            }

            internal MyMessageVisitor(int maxRecursionDepth) : base(maxRecursionDepth)
            {
                Assert.AreEqual(0, this.RecursionDepth);
            }
        }

        /// <summary>A <see cref="Body{T}"/> subclass to test whether the visitor throws for unknown types.</summary>
        private sealed class MyBody : Body<MyBody>
        {
            internal MyBody() : base("whatever")
            {
            }

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////

            /// <summary>See <see cref="Body.WriteTo(Stream, Action{IEnumerable{HeaderField}, bool})"/>.</summary>
            protected internal sealed override void WriteTo(
                Stream stream, Action<IEnumerable<HeaderField>, bool> writeHeaderFieldsCallback)
            {
                throw new NotImplementedException();
            }
        }

        /// <summary>A <see cref="Entity{T}"/> subclass to test whether the visitor throws for unknown types.</summary>
        private sealed class MyEntity : Entity<MyEntity>
        {
        }
    }
}
